12#include "apps/aomenc.h"
14#include "config/aom_config.h"
30#include "aom/aom_integer.h"
32#include "aom_dsp/aom_dsp_common.h"
33#include "aom_ports/aom_timer.h"
34#include "aom_ports/mem_ops.h"
35#include "common/args.h"
36#include "common/ivfenc.h"
37#include "common/tools_common.h"
38#include "common/warnings.h"
41#include "common/webmenc.h"
44#include "common/y4minput.h"
45#include "examples/encoder_util.h"
46#include "stats/aomstats.h"
47#include "stats/rate_hist.h"
50#include "third_party/libyuv/include/libyuv/scale.h"
54static size_t wrap_fread(
void *ptr,
size_t size,
size_t nmemb, FILE *stream) {
55 return fread(ptr, size, nmemb, stream);
57#define fread wrap_fread
59static size_t wrap_fwrite(
const void *ptr,
size_t size,
size_t nmemb,
61 return fwrite(ptr, size, nmemb, stream);
63#define fwrite wrap_fwrite
65static const char *exec_name;
67static AOM_TOOLS_FORMAT_PRINTF(3, 0) void warn_or_exit_on_errorv(
70 const char *detail = aom_codec_error_detail(ctx);
72 vfprintf(stderr, s, ap);
73 fprintf(stderr,
": %s\n", aom_codec_error(ctx));
75 if (detail) fprintf(stderr,
" %s\n", detail);
78 aom_codec_destroy(ctx);
84static AOM_TOOLS_FORMAT_PRINTF(2,
90 warn_or_exit_on_errorv(ctx, 1, s, ap);
94static AOM_TOOLS_FORMAT_PRINTF(3, 4) void warn_or_exit_on_error(
99 warn_or_exit_on_errorv(ctx, fatal, s, ap);
103static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
104 FILE *f = input_ctx->file;
105 y4m_input *y4m = &input_ctx->y4m;
108 if (input_ctx->file_type == FILE_TYPE_Y4M) {
109 if (y4m_input_fetch_frame(y4m, f, img) < 1)
return 0;
111 shortread = read_yuv_frame(input_ctx, img);
117static int file_is_y4m(
const char detect[4]) {
118 if (memcmp(detect,
"YUV4", 4) == 0) {
124static int fourcc_is_ivf(
const char detect[4]) {
125 if (memcmp(detect,
"DKIF", 4) == 0) {
223 AV1E_SET_ENABLE_DNL_DENOISING,
248static const arg_def_t *
const main_args[] = {
249 &g_av1_codec_arg_defs.help,
250 &g_av1_codec_arg_defs.use_cfg,
251 &g_av1_codec_arg_defs.debugmode,
252 &g_av1_codec_arg_defs.outputfile,
253 &g_av1_codec_arg_defs.codecarg,
254 &g_av1_codec_arg_defs.passes,
255 &g_av1_codec_arg_defs.pass_arg,
256 &g_av1_codec_arg_defs.fpf_name,
257 &g_av1_codec_arg_defs.limit,
258 &g_av1_codec_arg_defs.skip,
259 &g_av1_codec_arg_defs.good_dl,
260 &g_av1_codec_arg_defs.rt_dl,
261 &g_av1_codec_arg_defs.ai_dl,
262 &g_av1_codec_arg_defs.quietarg,
263 &g_av1_codec_arg_defs.verbosearg,
264 &g_av1_codec_arg_defs.psnrarg,
265 &g_av1_codec_arg_defs.use_webm,
266 &g_av1_codec_arg_defs.use_ivf,
267 &g_av1_codec_arg_defs.use_obu,
268 &g_av1_codec_arg_defs.q_hist_n,
269 &g_av1_codec_arg_defs.rate_hist_n,
270 &g_av1_codec_arg_defs.disable_warnings,
271 &g_av1_codec_arg_defs.disable_warning_prompt,
272 &g_av1_codec_arg_defs.recontest,
276static const arg_def_t *
const global_args[] = {
277 &g_av1_codec_arg_defs.use_nv12,
278 &g_av1_codec_arg_defs.use_yv12,
279 &g_av1_codec_arg_defs.use_i420,
280 &g_av1_codec_arg_defs.use_i422,
281 &g_av1_codec_arg_defs.use_i444,
282 &g_av1_codec_arg_defs.usage,
283 &g_av1_codec_arg_defs.threads,
284 &g_av1_codec_arg_defs.profile,
285 &g_av1_codec_arg_defs.width,
286 &g_av1_codec_arg_defs.height,
287 &g_av1_codec_arg_defs.forced_max_frame_width,
288 &g_av1_codec_arg_defs.forced_max_frame_height,
290 &g_av1_codec_arg_defs.stereo_mode,
292 &g_av1_codec_arg_defs.timebase,
293 &g_av1_codec_arg_defs.framerate,
294 &g_av1_codec_arg_defs.global_error_resilient,
295 &g_av1_codec_arg_defs.bitdeptharg,
296 &g_av1_codec_arg_defs.inbitdeptharg,
297 &g_av1_codec_arg_defs.lag_in_frames,
298 &g_av1_codec_arg_defs.large_scale_tile,
299 &g_av1_codec_arg_defs.monochrome,
300 &g_av1_codec_arg_defs.full_still_picture_hdr,
301 &g_av1_codec_arg_defs.use_16bit_internal,
302 &g_av1_codec_arg_defs.save_as_annexb,
306static const arg_def_t *
const rc_args[] = {
307 &g_av1_codec_arg_defs.dropframe_thresh,
308 &g_av1_codec_arg_defs.resize_mode,
309 &g_av1_codec_arg_defs.resize_denominator,
310 &g_av1_codec_arg_defs.resize_kf_denominator,
311 &g_av1_codec_arg_defs.superres_mode,
312 &g_av1_codec_arg_defs.superres_denominator,
313 &g_av1_codec_arg_defs.superres_kf_denominator,
314 &g_av1_codec_arg_defs.superres_qthresh,
315 &g_av1_codec_arg_defs.superres_kf_qthresh,
316 &g_av1_codec_arg_defs.end_usage,
317 &g_av1_codec_arg_defs.target_bitrate,
318 &g_av1_codec_arg_defs.min_quantizer,
319 &g_av1_codec_arg_defs.max_quantizer,
320 &g_av1_codec_arg_defs.undershoot_pct,
321 &g_av1_codec_arg_defs.overshoot_pct,
322 &g_av1_codec_arg_defs.buf_sz,
323 &g_av1_codec_arg_defs.buf_initial_sz,
324 &g_av1_codec_arg_defs.buf_optimal_sz,
325 &g_av1_codec_arg_defs.bias_pct,
326 &g_av1_codec_arg_defs.minsection_pct,
327 &g_av1_codec_arg_defs.maxsection_pct,
331static const arg_def_t *
const kf_args[] = {
332 &g_av1_codec_arg_defs.fwd_kf_enabled,
333 &g_av1_codec_arg_defs.kf_min_dist,
334 &g_av1_codec_arg_defs.kf_max_dist,
335 &g_av1_codec_arg_defs.kf_disabled,
336 &g_av1_codec_arg_defs.sframe_dist,
337 &g_av1_codec_arg_defs.sframe_mode,
343static const arg_def_t *
const av1_ctrl_args[] = {
344 &g_av1_codec_arg_defs.cpu_used_av1,
345 &g_av1_codec_arg_defs.auto_altref,
346 &g_av1_codec_arg_defs.sharpness,
347 &g_av1_codec_arg_defs.static_thresh,
348 &g_av1_codec_arg_defs.rowmtarg,
349 &g_av1_codec_arg_defs.fpmtarg,
350 &g_av1_codec_arg_defs.tile_cols,
351 &g_av1_codec_arg_defs.tile_rows,
352 &g_av1_codec_arg_defs.enable_tpl_model,
353 &g_av1_codec_arg_defs.enable_keyframe_filtering,
354 &g_av1_codec_arg_defs.arnr_maxframes,
355 &g_av1_codec_arg_defs.arnr_strength,
356 &g_av1_codec_arg_defs.tune_metric,
357 &g_av1_codec_arg_defs.cq_level,
358 &g_av1_codec_arg_defs.max_intra_rate_pct,
359 &g_av1_codec_arg_defs.max_inter_rate_pct,
360 &g_av1_codec_arg_defs.gf_cbr_boost_pct,
361 &g_av1_codec_arg_defs.lossless,
362 &g_av1_codec_arg_defs.enable_cdef,
363 &g_av1_codec_arg_defs.enable_restoration,
364 &g_av1_codec_arg_defs.enable_rect_partitions,
365 &g_av1_codec_arg_defs.enable_ab_partitions,
366 &g_av1_codec_arg_defs.enable_1to4_partitions,
367 &g_av1_codec_arg_defs.min_partition_size,
368 &g_av1_codec_arg_defs.max_partition_size,
369 &g_av1_codec_arg_defs.enable_dual_filter,
370 &g_av1_codec_arg_defs.enable_chroma_deltaq,
371 &g_av1_codec_arg_defs.enable_intra_edge_filter,
372 &g_av1_codec_arg_defs.enable_order_hint,
373 &g_av1_codec_arg_defs.enable_tx64,
374 &g_av1_codec_arg_defs.enable_flip_idtx,
375 &g_av1_codec_arg_defs.enable_rect_tx,
376 &g_av1_codec_arg_defs.enable_dist_wtd_comp,
377 &g_av1_codec_arg_defs.enable_masked_comp,
378 &g_av1_codec_arg_defs.enable_onesided_comp,
379 &g_av1_codec_arg_defs.enable_interintra_comp,
380 &g_av1_codec_arg_defs.enable_smooth_interintra,
381 &g_av1_codec_arg_defs.enable_diff_wtd_comp,
382 &g_av1_codec_arg_defs.enable_interinter_wedge,
383 &g_av1_codec_arg_defs.enable_interintra_wedge,
384 &g_av1_codec_arg_defs.enable_global_motion,
385 &g_av1_codec_arg_defs.enable_warped_motion,
386 &g_av1_codec_arg_defs.enable_filter_intra,
387 &g_av1_codec_arg_defs.enable_smooth_intra,
388 &g_av1_codec_arg_defs.enable_paeth_intra,
389 &g_av1_codec_arg_defs.enable_cfl_intra,
390 &g_av1_codec_arg_defs.enable_diagonal_intra,
391 &g_av1_codec_arg_defs.force_video_mode,
392 &g_av1_codec_arg_defs.enable_obmc,
393 &g_av1_codec_arg_defs.enable_overlay,
394 &g_av1_codec_arg_defs.enable_palette,
395 &g_av1_codec_arg_defs.enable_intrabc,
396 &g_av1_codec_arg_defs.enable_angle_delta,
397 &g_av1_codec_arg_defs.disable_trellis_quant,
398 &g_av1_codec_arg_defs.enable_qm,
399 &g_av1_codec_arg_defs.qm_min,
400 &g_av1_codec_arg_defs.qm_max,
401 &g_av1_codec_arg_defs.reduced_tx_type_set,
402 &g_av1_codec_arg_defs.use_intra_dct_only,
403 &g_av1_codec_arg_defs.use_inter_dct_only,
404 &g_av1_codec_arg_defs.use_intra_default_tx_only,
405 &g_av1_codec_arg_defs.quant_b_adapt,
406 &g_av1_codec_arg_defs.coeff_cost_upd_freq,
407 &g_av1_codec_arg_defs.mode_cost_upd_freq,
408 &g_av1_codec_arg_defs.mv_cost_upd_freq,
409 &g_av1_codec_arg_defs.frame_parallel_decoding,
410 &g_av1_codec_arg_defs.error_resilient_mode,
411 &g_av1_codec_arg_defs.aq_mode,
412 &g_av1_codec_arg_defs.deltaq_mode,
413 &g_av1_codec_arg_defs.deltaq_strength,
414 &g_av1_codec_arg_defs.deltalf_mode,
415 &g_av1_codec_arg_defs.frame_periodic_boost,
416 &g_av1_codec_arg_defs.noise_sens,
417 &g_av1_codec_arg_defs.tune_content,
418 &g_av1_codec_arg_defs.cdf_update_mode,
419 &g_av1_codec_arg_defs.input_color_primaries,
420 &g_av1_codec_arg_defs.input_transfer_characteristics,
421 &g_av1_codec_arg_defs.input_matrix_coefficients,
422 &g_av1_codec_arg_defs.input_chroma_sample_position,
423 &g_av1_codec_arg_defs.min_gf_interval,
424 &g_av1_codec_arg_defs.max_gf_interval,
425 &g_av1_codec_arg_defs.gf_min_pyr_height,
426 &g_av1_codec_arg_defs.gf_max_pyr_height,
427 &g_av1_codec_arg_defs.superblock_size,
428 &g_av1_codec_arg_defs.num_tg,
429 &g_av1_codec_arg_defs.mtu_size,
430 &g_av1_codec_arg_defs.timing_info,
431 &g_av1_codec_arg_defs.film_grain_test,
432 &g_av1_codec_arg_defs.film_grain_table,
434 &g_av1_codec_arg_defs.denoise_noise_level,
435 &g_av1_codec_arg_defs.denoise_block_size,
436 &g_av1_codec_arg_defs.enable_dnl_denoising,
438 &g_av1_codec_arg_defs.max_reference_frames,
439 &g_av1_codec_arg_defs.reduced_reference_set,
440 &g_av1_codec_arg_defs.enable_ref_frame_mvs,
441 &g_av1_codec_arg_defs.target_seq_level_idx,
442 &g_av1_codec_arg_defs.set_tier_mask,
443 &g_av1_codec_arg_defs.set_min_cr,
444 &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
445 &g_av1_codec_arg_defs.input_chroma_subsampling_x,
446 &g_av1_codec_arg_defs.input_chroma_subsampling_y,
448 &g_av1_codec_arg_defs.vmaf_model_path,
450 &g_av1_codec_arg_defs.dv_cost_upd_freq,
451 &g_av1_codec_arg_defs.partition_info_path,
452 &g_av1_codec_arg_defs.enable_directional_intra,
453 &g_av1_codec_arg_defs.enable_tx_size_search,
454 &g_av1_codec_arg_defs.loopfilter_control,
455 &g_av1_codec_arg_defs.auto_intra_tools_off,
456 &g_av1_codec_arg_defs.enable_rate_guide_deltaq,
457 &g_av1_codec_arg_defs.rate_distribution_info,
458 &g_av1_codec_arg_defs.enable_low_complexity_decode,
462static const arg_def_t *
const av1_key_val_args[] = {
463 &g_av1_codec_arg_defs.passes,
464 &g_av1_codec_arg_defs.two_pass_output,
465 &g_av1_codec_arg_defs.second_pass_log,
466 &g_av1_codec_arg_defs.fwd_kf_dist,
467 &g_av1_codec_arg_defs.strict_level_conformance,
468 &g_av1_codec_arg_defs.sb_qp_sweep,
469 &g_av1_codec_arg_defs.dist_metric,
470 &g_av1_codec_arg_defs.kf_max_pyr_height,
471 &g_av1_codec_arg_defs.auto_tiles,
475static const arg_def_t *
const no_args[] = { NULL };
477static void show_help(FILE *fout,
int shorthelp) {
478 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename\n",
482 fprintf(fout,
"Use --help to see the full list of options.\n");
486 fprintf(fout,
"\nOptions:\n");
487 arg_show_usage(fout, main_args);
488 fprintf(fout,
"\nEncoder Global Options:\n");
489 arg_show_usage(fout, global_args);
490 fprintf(fout,
"\nRate Control Options:\n");
491 arg_show_usage(fout, rc_args);
492 fprintf(fout,
"\nKeyframe Placement Options:\n");
493 arg_show_usage(fout, kf_args);
494#if CONFIG_AV1_ENCODER
495 fprintf(fout,
"\nAV1 Specific Options:\n");
496 arg_show_usage(fout, av1_ctrl_args);
497 arg_show_usage(fout, av1_key_val_args);
500 "\nStream timebase (--timebase):\n"
501 " The desired precision of timestamps in the output, expressed\n"
502 " in fractional seconds. Default is 1/1000.\n");
503 fprintf(fout,
"\nIncluded encoders:\n\n");
505 const int num_encoder = get_aom_encoder_count();
506 for (
int i = 0; i < num_encoder; ++i) {
508 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
509 fprintf(fout,
" %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
512 fprintf(fout,
"\n ");
513 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
516void usage_exit(
void) {
517 show_help(stderr, 1);
521#if CONFIG_AV1_ENCODER
522#define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
523#define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args)
527typedef int stereo_format_t;
528struct WebmOutputContext {
534struct stream_config {
537 const char *stats_fn;
538 stereo_format_t stereo_fmt;
539 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
541 const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2];
544 const char *film_grain_filename;
547 int use_16bit_internal;
549 const char *vmaf_model_path;
551 const char *partition_info_path;
552 unsigned int enable_rate_guide_deltaq;
553 const char *rate_distribution_info;
555 const char *two_pass_input;
556 const char *two_pass_output;
559 unsigned int enable_low_complexity_decode;
564 struct stream_state *next;
565 struct stream_config config;
567 struct rate_hist *rate_hist;
568 struct WebmOutputContext webm_ctx;
569 uint64_t psnr_sse_total[2];
570 uint64_t psnr_samples_total[2];
571 double psnr_totals[2][4];
575 unsigned int frames_out;
582 unsigned int chroma_subsampling_x;
583 unsigned int chroma_subsampling_y;
584 const char *orig_out_fn;
585 unsigned int orig_width;
586 unsigned int orig_height;
589 char tmp_out_fn[1000];
592static void validate_positive_rational(
const char *msg,
599 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
601 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
615static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
618 const int num_encoder = get_aom_encoder_count();
619 char **argv_local = (
char **)*argv;
620 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
623 memset(global, 0,
sizeof(*global));
624 global->codec = get_aom_encoder_by_index(num_encoder - 1);
626 global->color_type = I420;
628 global->show_psnr = 0;
630 int cfg_included = 0;
631 init_config(&global->encoder_config);
633 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
636 if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
638 parse_cfg(arg.val, &global->encoder_config);
641 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
642 show_help(stdout, 0);
644 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
645 global->codec = get_aom_encoder_by_short_name(arg.val);
647 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
648 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
649 global->passes = arg_parse_uint(&arg);
651 if (global->passes < 1 || global->passes > 3)
652 die(
"Error: Invalid number of passes (%d)\n", global->passes);
653 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
654 global->pass = arg_parse_uint(&arg);
656 if (global->pass < 1 || global->pass > 3)
657 die(
"Error: Invalid pass selected (%d)\n", global->pass);
658 }
else if (arg_match(&arg,
659 &g_av1_codec_arg_defs.input_chroma_sample_position,
661 global->csp = arg_parse_enum(&arg);
664 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
665 global->usage = arg_parse_uint(&arg);
666 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
668 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
670 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.ai_dl, argi)) {
672 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_nv12, argi)) {
673 global->color_type = NV12;
674 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
675 global->color_type = YV12;
676 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
677 global->color_type = I420;
678 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
679 global->color_type = I422;
680 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
681 global->color_type = I444;
682 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
684 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
686 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
687 global->limit = arg_parse_uint(&arg);
688 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
689 global->skip_frames = arg_parse_uint(&arg);
690 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
692 global->show_psnr = arg_parse_int(&arg);
694 global->show_psnr = 1;
695 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
696 global->test_decode = arg_parse_enum_or_int(&arg);
697 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
698 global->framerate = arg_parse_rational(&arg);
699 validate_positive_rational(arg.name, &global->framerate);
700 global->have_framerate = 1;
701 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
703 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
704 global->show_q_hist_buckets = arg_parse_uint(&arg);
705 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
706 global->show_rate_hist_buckets = arg_parse_uint(&arg);
707 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
708 global->disable_warnings = 1;
709 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
711 global->disable_warning_prompt = 1;
719 if (global->pass > global->passes) {
720 aom_tools_warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
722 global->passes = global->pass;
726 if (global->passes == 0) {
727#if CONFIG_AV1_ENCODER
730 if (global->codec != NULL)
732 (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0 &&
742 aom_tools_warn(
"Enforcing one-pass encoding in realtime mode\n");
743 if (global->pass > 1)
744 die(
"Error: Invalid --pass=%d for one-pass encoding\n", global->pass);
749 aom_tools_warn(
"Enforcing one-pass encoding in all intra mode\n");
754static void open_input_file(
struct AvxInputContext *input,
757 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
758 : set_binary_mode(stdin);
760 if (!input->file) fatal(
"Failed to open input file");
762 if (!fseeko(input->file, 0, SEEK_END)) {
766 input->length = ftello(input->file);
771 input->pixel_aspect_ratio.numerator = 1;
772 input->pixel_aspect_ratio.denominator = 1;
777 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
778 input->detect.position = 0;
780 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
781 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
782 input->only_i420) >= 0) {
783 input->file_type = FILE_TYPE_Y4M;
784 input->width = input->y4m.pic_w;
785 input->height = input->y4m.pic_h;
786 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
787 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
788 input->framerate.numerator = input->y4m.fps_n;
789 input->framerate.denominator = input->y4m.fps_d;
790 input->fmt = input->y4m.aom_fmt;
791 input->bit_depth = input->y4m.bit_depth;
792 input->color_range = input->y4m.color_range;
794 fatal(
"Unsupported Y4M stream.");
795 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
796 fatal(
"IVF is not supported as input.");
798 input->file_type = FILE_TYPE_RAW;
802static void close_input_file(
struct AvxInputContext *input) {
804 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
807static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
808 struct stream_state *prev) {
809 struct stream_state *stream;
811 stream = calloc(1,
sizeof(*stream));
812 if (stream == NULL) {
813 fatal(
"Failed to allocate new stream.");
817 memcpy(stream, prev,
sizeof(*stream));
831 stream->config.cfg.g_timebase.den = 1000;
836 stream->config.cfg.g_w = 0;
837 stream->config.cfg.g_h = 0;
840 stream->config.write_webm = 1;
841 stream->config.write_ivf = 0;
844 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
845 stream->webm_ctx.last_pts_ns = -1;
846 stream->webm_ctx.writer = NULL;
847 stream->webm_ctx.segment = NULL;
851 stream->webm_ctx.debug = global->debug;
852 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
853 sizeof(stream->config.cfg.encoder_cfg));
857 stream->config.out_fn = NULL;
858 stream->config.two_pass_input = NULL;
859 stream->config.two_pass_output = NULL;
860 stream->config.two_pass_width = 0;
861 stream->config.two_pass_height = 0;
867static void set_config_arg_ctrls(
struct stream_config *config,
int key,
868 const struct arg *arg) {
871 config->film_grain_filename = arg->val;
878 j = config->arg_ctrl_cnt;
879 assert(j < ARG_CTRL_CNT_MAX);
880 config->arg_ctrls[j][0] = key;
881 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
882 ++config->arg_ctrl_cnt;
889 for (j = 0; j < config->arg_ctrl_cnt; j++)
890 if (config->arg_ctrls[j][0] == key)
break;
893 assert(j < ARG_CTRL_CNT_MAX);
894 config->arg_ctrls[j][0] = key;
895 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
899 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
900 config->arg_ctrls[j][1] = 1;
903 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
906static void set_config_arg_key_vals(
struct stream_config *config,
907 const char *name,
const struct arg *arg) {
909 const char *val = arg->val;
912 if (strcmp(name,
"target-seq-level-idx") == 0) {
913 j = config->arg_key_val_cnt;
914 assert(j < ARG_KEY_VAL_CNT_MAX);
915 config->arg_key_vals[j][0] = name;
916 config->arg_key_vals[j][1] = val;
917 ++config->arg_key_val_cnt;
924 for (j = 0; j < config->arg_key_val_cnt; j++)
925 if (strcmp(name, config->arg_key_vals[j][0]) == 0)
break;
928 assert(j < ARG_KEY_VAL_CNT_MAX);
929 config->arg_key_vals[j][0] = name;
930 config->arg_key_vals[j][1] = val;
932 if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) {
933 int auto_altref = arg_parse_int(arg);
934 if (auto_altref > 1) {
936 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
937 config->arg_key_vals[j][1] =
"1";
941 if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++;
944static int parse_stream_params(
struct AvxEncoderConfig *global,
945 struct stream_state *stream,
char **argv) {
948 const arg_def_t *
const *ctrl_args = no_args;
949 const arg_def_t *
const *key_val_args = no_args;
950 const int *ctrl_args_map = NULL;
951 struct stream_config *config = &stream->config;
952 int eos_mark_found = 0;
957#if CONFIG_AV1_ENCODER
958 }
else if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
961#if __STDC_VERSION__ >= 201112L
962 _Static_assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map),
963 "The av1_ctrl_args and av1_arg_ctrl_map arrays must be of "
966 assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map));
968 ctrl_args = av1_ctrl_args;
969 ctrl_args_map = av1_arg_ctrl_map;
970 key_val_args = av1_key_val_args;
974 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
980 if (eos_mark_found) {
983 }
else if (!strcmp(*argj,
"--")) {
988 if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
989 config->out_fn = arg.val;
991 const size_t out_fn_len = strlen(config->out_fn);
992 if (out_fn_len >= 4 &&
993 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
994 config->write_webm = 0;
995 config->write_ivf = 1;
996 }
else if (out_fn_len >= 4 &&
997 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
998 config->write_webm = 0;
999 config->write_ivf = 0;
1002 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
1003 config->stats_fn = arg.val;
1004 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
1006 config->write_webm = 1;
1009 die(
"Error: --webm specified but webm is disabled.");
1011 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
1012 config->write_webm = 0;
1013 config->write_ivf = 1;
1014 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
1015 config->write_webm = 0;
1016 config->write_ivf = 0;
1017 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
1018 config->cfg.g_threads = arg_parse_uint(&arg);
1019 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
1020 config->cfg.g_profile = arg_parse_uint(&arg);
1021 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
1022 config->cfg.g_w = arg_parse_uint(&arg);
1023 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
1024 config->cfg.g_h = arg_parse_uint(&arg);
1025 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
1027 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
1028 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
1030 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
1031 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
1032 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
1033 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
1034 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
1035 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
1037 stream->chroma_subsampling_x = arg_parse_uint(&arg);
1038 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
1040 stream->chroma_subsampling_y = arg_parse_uint(&arg);
1042 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
1043 config->stereo_fmt = arg_parse_enum_or_int(&arg);
1045 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
1046 config->cfg.g_timebase = arg_parse_rational(&arg);
1047 validate_positive_rational(arg.name, &config->cfg.g_timebase);
1048 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
1050 config->cfg.g_error_resilient = arg_parse_uint(&arg);
1051 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
1052 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
1053 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
1054 config->cfg.large_scale_tile = arg_parse_uint(&arg);
1055 if (config->cfg.large_scale_tile) {
1056 global->codec = get_aom_encoder_by_short_name(
"av1");
1058 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
1059 config->cfg.monochrome = 1;
1060 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
1062 config->cfg.full_still_picture_hdr = 1;
1063 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
1065 config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
1066 if (!config->use_16bit_internal) {
1067 aom_tools_warn(
"%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n",
1070 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
1071 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
1072 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
1073 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
1074 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
1076 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1077 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
1079 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1080 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
1081 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1082 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
1084 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1085 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
1087 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1088 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
1089 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1090 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
1092 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1093 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
1094 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1095 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
1096 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1097 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
1098 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1099 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
1100 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1101 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
1102 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1103 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
1104 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1105 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
1106 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1107 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
1108 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1109 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
1110 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1111 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
1112 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1113 if (global->passes < 2)
1114 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1115 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
1116 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1118 if (global->passes < 2)
1119 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1120 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
1121 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1123 if (global->passes < 2)
1124 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1125 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
1126 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1127 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
1128 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1129 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
1130 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1131 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
1133 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
1134 config->cfg.sframe_dist = arg_parse_uint(&arg);
1135 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1136 config->cfg.sframe_mode = arg_parse_uint(&arg);
1137 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1138 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1139 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1140 config->cfg.tile_width_count =
1142 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1143 config->cfg.tile_height_count =
1146 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1147 config->vmaf_model_path = arg.val;
1149 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.partition_info_path,
1151 config->partition_info_path = arg.val;
1152 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.enable_rate_guide_deltaq,
1154 config->enable_rate_guide_deltaq = arg_parse_uint(&arg);
1155 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_distribution_info,
1157 config->rate_distribution_info = arg.val;
1158 }
else if (arg_match(&arg,
1159 &g_av1_codec_arg_defs.enable_low_complexity_decode,
1161 config->enable_low_complexity_decode = arg_parse_uint(&arg);
1162 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1164 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1165 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1166 config->cfg.use_fixed_qp_offsets = 1;
1168 arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1170 if (arg_parse_uint(&arg) == 1) {
1171 aom_tools_warn(
"non-zero %s option ignored in realtime mode.\n",
1174 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_input, argi)) {
1175 config->two_pass_input = arg.val;
1176 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_output, argi)) {
1177 config->two_pass_output = arg.val;
1178 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_width, argi)) {
1179 config->two_pass_width = arg_parse_int(&arg);
1180 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_height, argi)) {
1181 config->two_pass_height = arg_parse_int(&arg);
1185 if (ctrl_args_map) {
1186 for (i = 0; ctrl_args[i]; i++) {
1187 if (arg_match(&arg, ctrl_args[i], argi)) {
1189 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1196 for (i = 0; key_val_args[i]; i++) {
1197 if (arg_match(&arg, key_val_args[i], argi)) {
1199 set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg);
1207 config->use_16bit_internal |= config->cfg.g_bit_depth >
AOM_BITS_8;
1210 aom_tools_warn(
"non-zero lag-in-frames option ignored in realtime mode.\n");
1211 config->cfg.g_lag_in_frames = 0;
1215 if (config->cfg.g_lag_in_frames != 0) {
1217 "non-zero lag-in-frames option ignored in all intra mode.\n");
1218 config->cfg.g_lag_in_frames = 0;
1220 if (config->cfg.kf_max_dist != 0) {
1222 "non-zero max key frame distance option ignored in all intra "
1224 config->cfg.kf_max_dist = 0;
1229 if (config->arg_key_val_cnt >= ARG_KEY_VAL_CNT_MAX) {
1230 die(
"Not enough buffer for the key & value API.");
1232 config->arg_key_vals[config->arg_key_val_cnt][0] =
"passes";
1233 switch (global->passes) {
1234 case 0: config->arg_key_vals[config->arg_key_val_cnt][1] =
"0";
break;
1235 case 1: config->arg_key_vals[config->arg_key_val_cnt][1] =
"1";
break;
1236 case 2: config->arg_key_vals[config->arg_key_val_cnt][1] =
"2";
break;
1237 case 3: config->arg_key_vals[config->arg_key_val_cnt][1] =
"3";
break;
1238 default: die(
"Invalid value of --passes.");
1240 config->arg_key_val_cnt++;
1243 if (!config->two_pass_output && global->passes == 3) {
1245 snprintf(stream->tmp_out_fn,
sizeof(stream->tmp_out_fn),
1246 "%.980s_pass2_%d.ivf", stream->config.out_fn, stream->index);
1247 stream->config.two_pass_output = stream->tmp_out_fn;
1249 if (config->two_pass_output) {
1250 config->arg_key_vals[config->arg_key_val_cnt][0] =
"two-pass-output";
1251 config->arg_key_vals[config->arg_key_val_cnt][1] = config->two_pass_output;
1252 config->arg_key_val_cnt++;
1255 return eos_mark_found;
1258#define FOREACH_STREAM(iterator, list) \
1259 for (struct stream_state *iterator = list; iterator; \
1260 iterator = iterator->next)
1262static void validate_stream_config(
const struct stream_state *stream,
1263 const struct AvxEncoderConfig *global) {
1264 const struct stream_state *streami;
1267 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1269 "Stream %d: Specify stream dimensions with --width (-w) "
1270 " and --height (-h)",
1276 assert(stream->config.cfg.g_input_bit_depth <=
1277 (
unsigned int)stream->config.cfg.g_bit_depth);
1279 for (streami = stream; streami; streami = streami->next) {
1281 if (!streami->config.out_fn)
1282 fatal(
"Stream %d: Output file is required (specify with -o)",
1286 if (streami != stream) {
1287 const char *a = stream->config.out_fn;
1288 const char *b = streami->config.out_fn;
1289 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1290 fatal(
"Stream %d: duplicate output file (from stream %d)",
1291 streami->index, stream->index);
1295 if (streami != stream) {
1296 const char *a = stream->config.stats_fn;
1297 const char *b = streami->config.stats_fn;
1298 if (a && b && !strcmp(a, b))
1299 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1300 streami->index, stream->index);
1305static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1307 if (!stream->config.cfg.g_w) {
1308 if (!stream->config.cfg.g_h)
1309 stream->config.cfg.g_w = w;
1311 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1313 if (!stream->config.cfg.g_h) {
1314 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1318static const char *file_type_to_string(
enum VideoFileType t) {
1320 case FILE_TYPE_RAW:
return "RAW";
1321 case FILE_TYPE_Y4M:
return "Y4M";
1322 default:
return "Other";
1326static void show_stream_config(
struct stream_state *stream,
1327 struct AvxEncoderConfig *global,
1328 struct AvxInputContext *input) {
1329#define SHOW(field) \
1330 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1332 if (stream->index == 0) {
1334 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1335 input->filename, file_type_to_string(input->file_type),
1336 image_format_to_string(input->fmt));
1338 if (stream->next || stream->index)
1339 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1340 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1341 fprintf(stderr,
"Coding path: %s\n",
1342 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1343 fprintf(stderr,
"Encoder parameters:\n");
1351 SHOW(g_input_bit_depth);
1352 SHOW(g_timebase.num);
1353 SHOW(g_timebase.den);
1354 SHOW(g_error_resilient);
1356 SHOW(g_lag_in_frames);
1357 SHOW(large_scale_tile);
1358 SHOW(rc_dropframe_thresh);
1359 SHOW(rc_resize_mode);
1360 SHOW(rc_resize_denominator);
1361 SHOW(rc_resize_kf_denominator);
1362 SHOW(rc_superres_mode);
1363 SHOW(rc_superres_denominator);
1364 SHOW(rc_superres_kf_denominator);
1365 SHOW(rc_superres_qthresh);
1366 SHOW(rc_superres_kf_qthresh);
1368 SHOW(rc_target_bitrate);
1369 SHOW(rc_min_quantizer);
1370 SHOW(rc_max_quantizer);
1371 SHOW(rc_undershoot_pct);
1372 SHOW(rc_overshoot_pct);
1374 SHOW(rc_buf_initial_sz);
1375 SHOW(rc_buf_optimal_sz);
1376 SHOW(rc_2pass_vbr_bias_pct);
1377 SHOW(rc_2pass_vbr_minsection_pct);
1378 SHOW(rc_2pass_vbr_maxsection_pct);
1379 SHOW(fwd_kf_enabled);
1384#define SHOW_PARAMS(field) \
1385 fprintf(stderr, " %-28s = %d\n", #field, \
1386 stream->config.cfg.encoder_cfg.field)
1387 if (global->encoder_config.init_by_cfg_file) {
1388 SHOW_PARAMS(super_block_size);
1389 SHOW_PARAMS(max_partition_size);
1390 SHOW_PARAMS(min_partition_size);
1391 SHOW_PARAMS(disable_ab_partition_type);
1392 SHOW_PARAMS(disable_rect_partition_type);
1393 SHOW_PARAMS(disable_1to4_partition_type);
1394 SHOW_PARAMS(disable_flip_idtx);
1395 SHOW_PARAMS(disable_cdef);
1396 SHOW_PARAMS(disable_lr);
1397 SHOW_PARAMS(disable_obmc);
1398 SHOW_PARAMS(disable_warp_motion);
1399 SHOW_PARAMS(disable_global_motion);
1400 SHOW_PARAMS(disable_dist_wtd_comp);
1401 SHOW_PARAMS(disable_diff_wtd_comp);
1402 SHOW_PARAMS(disable_inter_intra_comp);
1403 SHOW_PARAMS(disable_masked_comp);
1404 SHOW_PARAMS(disable_one_sided_comp);
1405 SHOW_PARAMS(disable_palette);
1406 SHOW_PARAMS(disable_intrabc);
1407 SHOW_PARAMS(disable_cfl);
1408 SHOW_PARAMS(disable_smooth_intra);
1409 SHOW_PARAMS(disable_filter_intra);
1410 SHOW_PARAMS(disable_dual_filter);
1411 SHOW_PARAMS(disable_intra_angle_delta);
1412 SHOW_PARAMS(disable_intra_edge_filter);
1413 SHOW_PARAMS(disable_tx_64x64);
1414 SHOW_PARAMS(disable_smooth_inter_intra);
1415 SHOW_PARAMS(disable_inter_inter_wedge);
1416 SHOW_PARAMS(disable_inter_intra_wedge);
1417 SHOW_PARAMS(disable_paeth_intra);
1418 SHOW_PARAMS(disable_trellis_quant);
1419 SHOW_PARAMS(disable_ref_frame_mv);
1420 SHOW_PARAMS(reduced_reference_set);
1421 SHOW_PARAMS(reduced_tx_type_set);
1425static void open_output_file(
struct stream_state *stream,
1426 struct AvxEncoderConfig *global,
1427 const struct AvxRational *pixel_aspect_ratio,
1428 const char *encoder_settings) {
1429 const char *fn = stream->config.out_fn;
1434 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1436 if (!stream->file) fatal(
"Failed to open output file");
1438 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1439 fatal(
"WebM output to pipes not supported.");
1442 if (stream->config.write_webm) {
1443 stream->webm_ctx.stream = stream->file;
1444 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1445 stream->config.stereo_fmt,
1446 get_fourcc_by_aom_encoder(global->codec),
1447 pixel_aspect_ratio, encoder_settings) != 0) {
1448 fatal(
"WebM writer initialization failed.");
1452 (void)pixel_aspect_ratio;
1453 (void)encoder_settings;
1456 if (!stream->config.write_webm && stream->config.write_ivf) {
1457 ivf_write_file_header(stream->file, cfg,
1458 get_fourcc_by_aom_encoder(global->codec), 0);
1462static void close_output_file(
struct stream_state *stream,
1463 unsigned int fourcc) {
1469 if (stream->config.write_webm) {
1470 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1471 fatal(
"WebM writer finalization failed.");
1476 if (!stream->config.write_webm && stream->config.write_ivf) {
1477 if (!fseek(stream->file, 0, SEEK_SET))
1478 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1479 stream->frames_out);
1482 fclose(stream->file);
1485static void setup_pass(
struct stream_state *stream,
1486 struct AvxEncoderConfig *global,
int pass) {
1487 if (stream->config.stats_fn) {
1488 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1489 fatal(
"Failed to open statistics store");
1491 if (!stats_open_mem(&stream->stats, pass))
1492 fatal(
"Failed to open statistics store");
1495 if (global->passes == 1) {
1502 default: fatal(
"Failed to set pass");
1507 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1510 stream->cx_time = 0;
1512 stream->frames_out = 0;
1515static void initialize_encoder(
struct stream_state *stream,
1516 struct AvxEncoderConfig *global) {
1526 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1528 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1529 int ctrl = stream->config.arg_ctrls[i][0];
1530 int value = stream->config.arg_ctrls[i][1];
1532 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1534 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1537 for (i = 0; i < stream->config.arg_key_val_cnt; i++) {
1538 const char *name = stream->config.arg_key_vals[i][0];
1539 const char *val = stream->config.arg_key_vals[i][1];
1541 fprintf(stderr,
"Error: Tried to set option %s = %s\n", name, val);
1543 ctx_exit_on_error(&stream->encoder,
"Failed to set codec option");
1547 if (stream->config.vmaf_model_path) {
1549 stream->config.vmaf_model_path);
1550 ctx_exit_on_error(&stream->encoder,
"Failed to set vmaf model path");
1553 if (stream->config.partition_info_path) {
1556 stream->config.partition_info_path);
1557 ctx_exit_on_error(&stream->encoder,
"Failed to set partition info path");
1559 if (stream->config.enable_rate_guide_deltaq) {
1562 stream->config.enable_rate_guide_deltaq);
1563 ctx_exit_on_error(&stream->encoder,
"Failed to enable rate guide deltaq");
1565 if (stream->config.rate_distribution_info) {
1568 stream->config.rate_distribution_info);
1569 ctx_exit_on_error(&stream->encoder,
"Failed to set rate distribution info");
1572 if (stream->config.enable_low_complexity_decode) {
1575 stream->config.enable_low_complexity_decode);
1576 ctx_exit_on_error(&stream->encoder,
1577 "Failed to enable low complexity decode");
1580 if (stream->config.film_grain_filename) {
1582 stream->config.film_grain_filename);
1583 ctx_exit_on_error(&stream->encoder,
"Failed to set film grain table");
1586 stream->config.color_range);
1587 ctx_exit_on_error(&stream->encoder,
"Failed to set color range");
1589#if CONFIG_AV1_DECODER
1590 if (global->test_decode != TEST_DECODE_OFF) {
1592 get_short_name_by_aom_encoder(global->codec));
1596 if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
1598 stream->config.cfg.large_scale_tile);
1599 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1602 stream->config.cfg.save_as_annexb);
1603 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1607 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1611 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1622static void convert_image_to_monochrome(
const struct aom_image *img,
1624 *monochrome_img = *img;
1637 monochrome_img->
sz = 0;
1644static void encode_frame(
struct stream_state *stream,
1645 struct AvxEncoderConfig *global,
struct aom_image *img,
1646 unsigned int frames_in) {
1649 struct aom_usec_timer timer;
1652 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1655 (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) /
1656 cfg->g_timebase.num / global->framerate.num;
1661 (img->
d_w != cfg->g_w || img->
d_h != cfg->g_h)) {
1663 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1680 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1681 stream->img->d_h, kFilterBox);
1684 stream->encoder.err = 1;
1685 ctx_exit_on_error(&stream->encoder,
1686 "Stream %d: Failed to encode frame.\n"
1687 "libyuv is required for scaling but is currently "
1689 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1695 if (img && (img->
d_w != cfg->g_w || img->
d_h != cfg->g_h)) {
1697 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1711 stream->img->d_w, stream->img->d_h, kFilterBox);
1714 stream->encoder.err = 1;
1715 ctx_exit_on_error(&stream->encoder,
1716 "Stream %d: Failed to encode frame.\n"
1717 "Scaling disabled in this configuration. \n"
1718 "To enable, configure with --enable-libyuv\n",
1724 if (img && cfg->monochrome) {
1725 convert_image_to_monochrome(img, &monochrome_img);
1726 img = &monochrome_img;
1729 aom_usec_timer_start(&timer);
1731 (uint32_t)(next_frame_start - frame_start), 0);
1732 aom_usec_timer_mark(&timer);
1733 stream->cx_time += aom_usec_timer_elapsed(&timer);
1734 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
1738static void update_quantizer_histogram(
struct stream_state *stream) {
1744 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
1745 stream->counts[q]++;
1749static void get_cx_data(
struct stream_state *stream,
1750 struct AvxEncoderConfig *global,
int *got_data) {
1757 static size_t fsize = 0;
1758 static FileOffset ivf_header_pos = 0;
1760 switch (pkt->
kind) {
1762 ++stream->frames_out;
1764 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.
sz);
1766 update_rate_histogram(stream->rate_hist, cfg, pkt);
1768 if (stream->config.write_webm) {
1769 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1770 fatal(
"WebM writer failed.");
1774 if (!stream->config.write_webm) {
1775 if (stream->config.write_ivf) {
1777 ivf_header_pos = ftello(stream->file);
1780 ivf_write_frame_header(stream->file, pkt->
data.
frame.
pts, fsize);
1784 const FileOffset currpos = ftello(stream->file);
1785 fseeko(stream->file, ivf_header_pos, SEEK_SET);
1786 ivf_write_frame_size(stream->file, fsize);
1787 fseeko(stream->file, currpos, SEEK_SET);
1797#if CONFIG_AV1_DECODER
1798 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1801 if (stream->decoder.err) {
1802 warn_or_exit_on_error(&stream->decoder,
1803 global->test_decode == TEST_DECODE_FATAL,
1804 "Failed to decode frame %d in stream %d",
1805 stream->frames_out + 1, stream->index);
1806 stream->mismatch_seen = stream->frames_out + 1;
1812 stream->frames_out++;
1819 if (global->show_psnr >= 1) {
1822 stream->psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
1823 stream->psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
1824 for (i = 0; i < 4; i++) {
1826 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
1827 stream->psnr_totals[0][i] += pkt->
data.
psnr.psnr[i];
1829 stream->psnr_count[0]++;
1831#if CONFIG_AV1_HIGHBITDEPTH
1832 if (stream->config.cfg.g_input_bit_depth <
1833 (
unsigned int)stream->config.cfg.g_bit_depth) {
1834 stream->psnr_sse_total[1] += pkt->
data.
psnr.sse_hbd[0];
1835 stream->psnr_samples_total[1] += pkt->
data.
psnr.samples_hbd[0];
1836 for (i = 0; i < 4; i++) {
1838 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr_hbd[i]);
1839 stream->psnr_totals[1][i] += pkt->
data.
psnr.psnr_hbd[i];
1841 stream->psnr_count[1]++;
1852static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
1856 if (!stream->psnr_count[0])
return;
1858 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1859 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[0], peak,
1860 (
double)stream->psnr_sse_total[0]);
1861 fprintf(stderr,
" %.3f", ovpsnr);
1863 for (i = 0; i < 4; i++) {
1864 fprintf(stderr,
" %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1867 fprintf(stderr,
" %7" PRId64
" bps", bps);
1869 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1870 fprintf(stderr,
"\n");
1873#if CONFIG_AV1_HIGHBITDEPTH
1874static void show_psnr_hbd(
struct stream_state *stream,
double peak,
1879 if (!stream->psnr_count[1])
return;
1881 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1882 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[1], peak,
1883 (
double)stream->psnr_sse_total[1]);
1884 fprintf(stderr,
" %.3f", ovpsnr);
1886 for (i = 0; i < 4; i++) {
1887 fprintf(stderr,
" %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1890 fprintf(stderr,
" %7" PRId64
" bps", bps);
1892 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1893 fprintf(stderr,
"\n");
1897static float usec_to_fps(uint64_t usec,
unsigned int frames) {
1898 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1901static void test_decode(
struct stream_state *stream,
1902 enum TestDecodeFatality fatal) {
1905 if (stream->mismatch_seen)
return;
1918 enc_img.
d_w, enc_img.
d_h, 16);
1919 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1920 enc_img = enc_hbd_img;
1925 dec_img.
d_w, dec_img.
d_h, 16);
1926 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1927 dec_img = dec_hbd_img;
1931 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
1932 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
1934 if (!aom_compare_img(&enc_img, &dec_img)) {
1935 int y[4], u[4], v[4];
1937 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1939 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1941 stream->decoder.err = 1;
1942 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1943 "Stream %d: Encode/decode mismatch on frame %d at"
1944 " Y[%d, %d] {%d/%d},"
1945 " U[%d, %d] {%d/%d},"
1946 " V[%d, %d] {%d/%d}",
1947 stream->index, stream->frames_out, y[0], y[1], y[2],
1948 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1949 stream->mismatch_seen = stream->frames_out;
1956static void print_time(
const char *label, int64_t etl) {
1963 etl -= hours * 3600;
1968 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
1971 fprintf(stderr,
"[%3s unknown] ", label);
1975static void clear_stream_count_state(
struct stream_state *stream) {
1977 for (
int k = 0; k < 2; k++) {
1978 stream->psnr_sse_total[k] = 0;
1979 stream->psnr_samples_total[k] = 0;
1980 for (
int i = 0; i < 4; i++) {
1981 stream->psnr_totals[k][i] = 0;
1983 stream->psnr_count[k] = 0;
1986 memset(stream->counts, 0,
sizeof(stream->counts));
1995static int pass_need_downscale(
int global_pass,
int global_passes,
int pass) {
1996 return !global_pass && global_passes > 2 && pass == 1;
1999int main(
int argc,
const char **argv_) {
2003 int allocated_raw_shift = 0;
2004 int do_16bit_internal = 0;
2005 int input_shift = 0;
2006 int frame_avail, got_data;
2008 struct AvxInputContext input;
2009 struct AvxEncoderConfig global;
2010 struct stream_state *streams = NULL;
2011 char **argv, **argi;
2012 uint64_t cx_time = 0;
2015 int profile_updated = 0;
2017 memset(&input, 0,
sizeof(input));
2018 memset(&raw, 0,
sizeof(raw));
2019 exec_name = argv_[0];
2022 input.framerate.numerator = 30;
2023 input.framerate.denominator = 1;
2024 input.only_i420 = 1;
2025 input.bit_depth = 0;
2031 argv = argv_dup(argc - 1, argv_ + 1);
2033 fprintf(stderr,
"Error allocating argument list\n");
2034 return EXIT_FAILURE;
2036 parse_global_config(&global, &argv);
2038 if (argc < 2) usage_exit();
2040 switch (global.color_type) {
2053 struct stream_state *stream = NULL;
2056 stream = new_stream(&global, stream);
2058 if (!streams) streams = stream;
2059 }
while (parse_stream_params(&global, stream, argv));
2063 for (argi = argv; *argi; argi++)
2064 if (argi[0][0] ==
'-' && argi[0][1])
2065 die(
"Error: Unrecognized option %s\n", *argi);
2067 FOREACH_STREAM(stream, streams) {
2068 check_encoder_config(global.disable_warning_prompt, &global,
2069 &stream->config.cfg);
2072 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
2073 die(
"only support ivf output format while large-scale-tile=1\n");
2077 input.filename = argv[0];
2078 const char *orig_input_filename = input.filename;
2079 FOREACH_STREAM(stream, streams) {
2080 stream->orig_out_fn = stream->config.out_fn;
2081 stream->orig_width = stream->config.cfg.g_w;
2082 stream->orig_height = stream->config.cfg.g_h;
2083 stream->orig_write_ivf = stream->config.write_ivf;
2084 stream->orig_write_webm = stream->config.write_webm;
2087 if (!input.filename) {
2088 fprintf(stderr,
"No input file specified!\n");
2093 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
2094 input.only_i420 = 0;
2096 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
2098 FOREACH_STREAM(stream, streams) { clear_stream_count_state(stream); }
2101 int frames_in = 0, seen_frames = 0;
2102 int64_t estimated_time_left = -1;
2103 int64_t average_rate = -1;
2104 int64_t lagged_count = 0;
2105 const int need_downscale =
2106 pass_need_downscale(global.pass, global.passes, pass);
2110 FOREACH_STREAM(stream, streams) {
2111 if (need_downscale) {
2112 stream->config.out_fn = stream->config.two_pass_output;
2114 stream->config.write_ivf = 1;
2115 stream->config.write_webm = 0;
2117 stream->config.out_fn = stream->orig_out_fn;
2118 stream->config.write_ivf = stream->orig_write_ivf;
2119 stream->config.write_webm = stream->orig_write_webm;
2121 stream->config.cfg.g_w = stream->orig_width;
2122 stream->config.cfg.g_h = stream->orig_height;
2128 input.filename = orig_input_filename;
2129 const char *two_pass_input = NULL;
2130 if (need_downscale) {
2131 FOREACH_STREAM(stream, streams) {
2132 if (stream->config.two_pass_input) {
2133 two_pass_input = stream->config.two_pass_input;
2134 input.filename = two_pass_input;
2140 open_input_file(&input, global.csp);
2145 if (!input.width || !input.height) {
2146 if (two_pass_input) {
2147 FOREACH_STREAM(stream, streams) {
2148 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2149 input.width = stream->config.two_pass_width;
2150 input.height = stream->config.two_pass_height;
2155 FOREACH_STREAM(stream, streams) {
2156 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
2157 input.width = stream->config.cfg.g_w;
2158 input.height = stream->config.cfg.g_h;
2166 if (!input.width || !input.height) {
2167 if (two_pass_input) {
2169 "Specify downscaled stream dimensions with --two-pass-width "
2170 " and --two-pass-height");
2173 "Specify stream dimensions with --width (-w) "
2174 " and --height (-h)");
2178 if (need_downscale) {
2179 FOREACH_STREAM(stream, streams) {
2180 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2181 stream->config.cfg.g_w = stream->config.two_pass_width;
2182 stream->config.cfg.g_h = stream->config.two_pass_height;
2183 }
else if (two_pass_input) {
2184 stream->config.cfg.g_w = input.width;
2185 stream->config.cfg.g_h = input.height;
2186 }
else if (stream->orig_width && stream->orig_height) {
2187#if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL
2188 stream->config.cfg.g_w = stream->orig_width;
2189 stream->config.cfg.g_h = stream->orig_height;
2191 stream->config.cfg.g_w = (stream->orig_width + 1) / 2;
2192 stream->config.cfg.g_h = (stream->orig_height + 1) / 2;
2195#if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL
2196 stream->config.cfg.g_w = input.width;
2197 stream->config.cfg.g_h = input.height;
2199 stream->config.cfg.g_w = (input.width + 1) / 2;
2200 stream->config.cfg.g_h = (input.height + 1) / 2;
2211 if (!input.bit_depth) {
2212 FOREACH_STREAM(stream, streams) {
2213 if (stream->config.cfg.g_input_bit_depth)
2214 input.bit_depth = stream->config.cfg.g_input_bit_depth;
2216 input.bit_depth = stream->config.cfg.g_input_bit_depth =
2217 (int)stream->config.cfg.g_bit_depth;
2221 FOREACH_STREAM(stream, streams) {
2222 stream->config.cfg.g_input_bit_depth = input.bit_depth;
2226 FOREACH_STREAM(stream, streams) {
2231 switch (stream->config.cfg.g_profile) {
2235 if (!stream->config.cfg.monochrome) {
2236 stream->config.cfg.g_profile = 1;
2237 profile_updated = 1;
2239 }
else if (input.bit_depth == 12 ||
2242 !stream->config.cfg.monochrome)) {
2243 stream->config.cfg.g_profile = 2;
2244 profile_updated = 1;
2250 stream->config.cfg.g_profile = 2;
2251 profile_updated = 1;
2252 }
else if (input.bit_depth < 12 &&
2255 stream->config.cfg.g_profile = 0;
2256 profile_updated = 1;
2262 stream->config.cfg.g_profile = 1;
2263 profile_updated = 1;
2264 }
else if (input.bit_depth < 12 &&
2267 stream->config.cfg.g_profile = 0;
2268 profile_updated = 1;
2269 }
else if (input.bit_depth == 12 &&
2270 input.file_type == FILE_TYPE_Y4M) {
2275 input.y4m.dst_c_dec_h >> 1);
2276 ctx_exit_on_error(&stream->encoder,
2277 "Failed to set chroma subsampling x");
2280 input.y4m.dst_c_dec_v >> 1);
2281 ctx_exit_on_error(&stream->encoder,
2282 "Failed to set chroma subsampling y");
2283 }
else if (input.bit_depth == 12 &&
2284 input.file_type == FILE_TYPE_RAW) {
2287 stream->chroma_subsampling_x);
2288 ctx_exit_on_error(&stream->encoder,
2289 "Failed to set chroma subsampling x");
2292 stream->chroma_subsampling_y);
2293 ctx_exit_on_error(&stream->encoder,
2294 "Failed to set chroma subsampling y");
2302 if (stream->config.cfg.g_input_bit_depth >
2303 (
unsigned int)stream->config.cfg.g_bit_depth) {
2304 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
2305 if (!global.quiet) {
2307 "Warning: automatically updating bit depth to %d to "
2308 "match input format.\n",
2309 stream->config.cfg.g_input_bit_depth);
2312#if !CONFIG_AV1_HIGHBITDEPTH
2313 if (stream->config.cfg.g_bit_depth > 8) {
2314 fatal(
"Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
2317 if (stream->config.cfg.g_bit_depth > 10) {
2318 switch (stream->config.cfg.g_profile) {
2321 stream->config.cfg.g_profile = 2;
2322 profile_updated = 1;
2327 if (stream->config.cfg.g_bit_depth > 8) {
2328 stream->config.use_16bit_internal = 1;
2330 if (profile_updated && !global.quiet) {
2332 "Warning: automatically updating to profile %d to "
2333 "match input format.\n",
2334 stream->config.cfg.g_profile);
2336 if (global.show_psnr == 2 &&
2337 stream->config.cfg.g_input_bit_depth ==
2338 (
unsigned int)stream->config.cfg.g_bit_depth) {
2340 "Warning: --psnr==2 and --psnr==1 will provide same "
2341 "results when input bit-depth == stream bit-depth, "
2342 "falling back to default psnr value\n");
2343 global.show_psnr = 1;
2345 if (global.show_psnr < 0 || global.show_psnr > 2) {
2347 "Warning: --psnr can take only 0,1,2 as values,"
2348 "falling back to default psnr value\n");
2349 global.show_psnr = 1;
2352 stream->config.cfg.g_limit = global.limit;
2355 FOREACH_STREAM(stream, streams) {
2356 set_stream_dimensions(stream, input.width, input.height);
2357 stream->config.color_range = input.color_range;
2359 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2364 if (global.pass > 0 && global.pass <= 3 && global.passes >= 2) {
2365 FOREACH_STREAM(stream, streams) {
2366 if (!stream->config.stats_fn)
2367 die(
"Stream %d: Must specify --fpf when --pass=%d"
2368 " and --passes=%d\n",
2369 stream->index, global.pass, global.passes);
2374 FOREACH_STREAM(stream, streams) {
2375 if (stream->config.write_webm) {
2376 stream->config.write_webm = 0;
2377 stream->config.write_ivf = 0;
2378 aom_tools_warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
2386 if (!global.have_framerate) {
2387 global.framerate.num = input.framerate.numerator;
2388 global.framerate.den = input.framerate.denominator;
2390 FOREACH_STREAM(stream, streams) {
2391 stream->config.cfg.g_timebase.den = global.framerate.num;
2392 stream->config.cfg.g_timebase.num = global.framerate.den;
2395 if (global.verbose && pass == 0) {
2396 FOREACH_STREAM(stream, streams) {
2397 show_stream_config(stream, &global, &input);
2401 if (pass == (global.pass ? global.pass - 1 : 0)) {
2403 if (input.file_type != FILE_TYPE_Y4M) {
2404 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2406 FOREACH_STREAM(stream, streams) {
2408 init_rate_histogram(&stream->config.cfg, &global.framerate);
2412 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2413 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2414 FOREACH_STREAM(stream, streams) {
2415 char *encoder_settings = NULL;
2424 if (stream->config.write_webm && !stream->webm_ctx.debug) {
2425 encoder_settings = extract_encoder_settings(
2427 if (encoder_settings == NULL) {
2430 "Warning: unable to extract encoder settings. Continuing...\n");
2434 open_output_file(stream, &global, &input.pixel_aspect_ratio,
2436 free(encoder_settings);
2439 if (strcmp(get_short_name_by_aom_encoder(global.codec),
"av1") == 0) {
2443 FOREACH_STREAM(stream, streams) {
2444 if (stream->config.use_16bit_internal) {
2445 do_16bit_internal = 1;
2447 input_shift = (int)stream->config.cfg.g_bit_depth -
2448 stream->config.cfg.g_input_bit_depth;
2455 while (frame_avail || got_data) {
2456 struct aom_usec_timer timer;
2458 if (!global.limit || frames_in < global.limit) {
2459 frame_avail = read_frame(&input, &raw);
2461 if (frame_avail) frames_in++;
2463 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2465 if (!global.quiet) {
2466 float fps = usec_to_fps(cx_time, seen_frames);
2467 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2469 if (stream_cnt == 1)
2470 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2471 streams->frames_out, (int64_t)streams->nbytes);
2473 fprintf(stderr,
"frame %4d ", frames_in);
2475 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2476 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2477 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2478 fps >= 1.0 ?
"fps" :
"fpm");
2479 print_time(
"ETA", estimated_time_left);
2491 if (frames_in > global.skip_frames) {
2493 if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2494 assert(do_16bit_internal);
2497 if (!allocated_raw_shift) {
2499 input.width, input.height, 32);
2500 allocated_raw_shift = 1;
2502 aom_img_upshift(&raw_shift, &raw, input_shift);
2503 frame_to_encode = &raw_shift;
2505 frame_to_encode = &raw;
2507 aom_usec_timer_start(&timer);
2508 if (do_16bit_internal) {
2510 FOREACH_STREAM(stream, streams) {
2511 if (stream->config.use_16bit_internal)
2512 encode_frame(stream, &global,
2513 frame_avail ? frame_to_encode : NULL, frames_in);
2519 FOREACH_STREAM(stream, streams) {
2520 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2524 aom_usec_timer_mark(&timer);
2525 cx_time += aom_usec_timer_elapsed(&timer);
2527 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2530 FOREACH_STREAM(stream, streams) {
2531 get_cx_data(stream, &global, &got_data);
2534 if (!got_data && input.length && streams != NULL &&
2535 !streams->frames_out) {
2536 lagged_count = global.limit ? seen_frames : ftello(input.file);
2537 }
else if (input.length) {
2542 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2544 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2545 remaining = 1000 * (global.limit - global.skip_frames -
2546 seen_frames + lagged_count);
2548 const int64_t input_pos = ftello(input.file);
2549 const int64_t input_pos_lagged = input_pos - lagged_count;
2550 const int64_t input_limit = input.length;
2552 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2553 remaining = input_limit - input_pos + lagged_count;
2557 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2558 estimated_time_left = average_rate ? remaining / average_rate : -1;
2561 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2562 FOREACH_STREAM(stream, streams) {
2563 test_decode(stream, global.test_decode);
2569 if (!global.quiet) fprintf(stderr,
"\033[K");
2572 if (stream_cnt > 1) fprintf(stderr,
"\n");
2574 if (!global.quiet) {
2575 FOREACH_STREAM(stream, streams) {
2577 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2578 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2580 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2583 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2584 pass + 1, global.passes, frames_in, stream->frames_out,
2585 (int64_t)stream->nbytes, bpf, bps,
2586 stream->cx_time > 9999999 ? stream->cx_time / 1000
2588 stream->cx_time > 9999999 ?
"ms" :
"us",
2589 usec_to_fps(stream->cx_time, seen_frames));
2595 if (global.show_psnr >= 1) {
2596 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2597 FOREACH_STREAM(stream, streams) {
2599 if (global.show_psnr == 1) {
2600 if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2601 bps = (int64_t)stream->nbytes * 8 *
2602 (int64_t)global.framerate.num / global.framerate.den /
2605 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2608 if (global.show_psnr == 2) {
2609#if CONFIG_AV1_HIGHBITDEPTH
2610 if (stream->config.cfg.g_input_bit_depth <
2611 (
unsigned int)stream->config.cfg.g_bit_depth)
2612 show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2618 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2622 if (pass == global.passes - 1) {
2623 FOREACH_STREAM(stream, streams) {
2624 int num_operating_points;
2626 int target_levels[32];
2628 &num_operating_points);
2633 for (
int i = 0; i < num_operating_points; i++) {
2634 if (levels[i] > target_levels[i]) {
2635 if (levels[i] == 31) {
2637 "Failed to encode to target level %d.%d for operating point "
2638 "%d. The output level is SEQ_LEVEL_MAX",
2639 2 + (target_levels[i] >> 2), target_levels[i] & 3, i);
2642 "Failed to encode to target level %d.%d for operating point "
2643 "%d. The output level is %d.%d",
2644 2 + (target_levels[i] >> 2), target_levels[i] & 3, i,
2645 2 + (levels[i] >> 2), levels[i] & 3);
2654 if (global.test_decode != TEST_DECODE_OFF) {
2658 close_input_file(&input);
2660 if (global.test_decode == TEST_DECODE_FATAL) {
2661 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2663 FOREACH_STREAM(stream, streams) {
2664 close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2667 FOREACH_STREAM(stream, streams) {
2668 stats_close(&stream->stats, global.passes - 1);
2671 if (global.pass)
break;
2674 if (global.show_q_hist_buckets) {
2675 FOREACH_STREAM(stream, streams) {
2676 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2680 if (global.show_rate_hist_buckets) {
2681 FOREACH_STREAM(stream, streams) {
2682 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2683 global.show_rate_hist_buckets);
2686 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2688#if CONFIG_INTERNAL_STATS
2692 if (!(global.pass == 1 && global.passes == 2)) {
2693 FOREACH_STREAM(stream, streams) {
2694 FILE *f = fopen(
"opsnr.stt",
"a");
2695 if (stream->mismatch_seen) {
2696 fprintf(f,
"First mismatch occurred in frame %d\n",
2697 stream->mismatch_seen);
2699 fprintf(f,
"No mismatch detected in recon buffers\n");
2710 return res ? EXIT_FAILURE : EXIT_SUCCESS;
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
#define MAX_TILE_WIDTHS
Maximum number of tile widths in tile widths array.
Definition aom_encoder.h:866
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition aom_encoder.h:879
#define AOM_PLANE_U
Definition aom_image.h:211
@ AOM_CSP_UNKNOWN
Definition aom_image.h:143
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_PLANE_Y
Definition aom_image.h:210
#define AOM_PLANE_V
Definition aom_image.h:212
enum aom_color_range aom_color_range_t
List of supported color range.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I42216
Definition aom_image.h:58
@ AOM_IMG_FMT_I42016
Definition aom_image.h:56
@ AOM_IMG_FMT_I444
Definition aom_image.h:50
@ AOM_IMG_FMT_I422
Definition aom_image.h:49
@ AOM_IMG_FMT_I44416
Definition aom_image.h:59
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
@ AOM_IMG_FMT_NV12
Definition aom_image.h:54
@ AOM_IMG_FMT_YV12
Definition aom_image.h:43
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
@ AV1_SET_TILE_MODE
Codec control function to set the tile coding mode, unsigned int parameter.
Definition aomdx.h:316
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition aomdx.h:352
@ AV1_SET_DECODE_TILE_ROW
Codec control function to set the range of tile decoding, int parameter.
Definition aomdx.h:307
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info, int parameter.
Definition aomcx.h:579
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition aomcx.h:1017
@ AV1E_SET_ENABLE_DIAGONAL_INTRA
Codec control function to turn on / off D45 to D203 intra mode usage, int parameter.
Definition aomcx.h:1356
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition aomcx.h:600
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition aomcx.h:367
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition aomcx.h:1077
@ AOME_SET_SHARPNESS
Codec control function to set the sharpness parameter, unsigned int parameter.
Definition aomcx.h:247
@ AV1E_GET_TARGET_SEQ_LEVEL_IDX
Codec control function to get the target sequence level index for each operating point....
Definition aomcx.h:1463
@ AV1E_SET_RATE_DISTRIBUTION_INFO
Codec control to set the input file for rate distribution used in all intra mode, const char * parame...
Definition aomcx.h:1522
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition aomcx.h:414
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition aomcx.h:269
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition aomcx.h:474
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition aomcx.h:1233
@ AV1E_GET_NUM_OPERATING_POINTS
Codec control function to get the number of operating points. int* parameter.
Definition aomcx.h:1468
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition aomcx.h:1328
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition aomcx.h:1085
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition aomcx.h:503
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition aomcx.h:512
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition aomcx.h:1196
@ AV1E_SET_COLOR_RANGE
Codec control function to set color range bit, int parameter.
Definition aomcx.h:612
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition aomcx.h:687
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition aomcx.h:1124
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition aomcx.h:593
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition aomcx.h:274
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition aomcx.h:1263
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition aomcx.h:1212
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition aomcx.h:558
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition aomcx.h:807
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition aomcx.h:714
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition aomcx.h:1120
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition aomcx.h:825
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition aomcx.h:993
@ AV1E_SET_FILM_GRAIN_TEST_VECTOR
Codec control function to add film grain parameters (one of several preset types) info in the bitstre...
Definition aomcx.h:1182
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes for a sequence,...
Definition aomcx.h:969
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition aomcx.h:961
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition aomcx.h:437
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition aomcx.h:844
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition aomcx.h:1045
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition aomcx.h:694
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition aomcx.h:1199
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition aomcx.h:863
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition aomcx.h:1243
@ AV1E_SET_ENABLE_DIRECTIONAL_INTRA
Codec control function to turn on / off directional intra mode usage, int parameter.
Definition aomcx.h:1385
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition aomcx.h:331
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition aomcx.h:1190
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition aomcx.h:1205
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition aomcx.h:404
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition aomcx.h:942
@ AV1E_SET_FP_MT
Codec control function to enable frame parallel multi-threading of the encoder, unsigned int paramete...
Definition aomcx.h:1443
@ AV1E_SET_ENABLE_MASKED_COMP
Codec control function to turn on / off masked compound usage (wedge and diff-wtd compound modes) for...
Definition aomcx.h:977
@ AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP
Control to set average complexity of the corpus in the case of single pass vbr based on LAP,...
Definition aomcx.h:1333
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition aomcx.h:1222
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition aomcx.h:677
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition aomcx.h:907
@ AV1E_GET_SEQ_LEVEL_IDX
Codec control function to get sequence level index for each operating point. int* parameter....
Definition aomcx.h:649
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition aomcx.h:486
@ AV1E_SET_DV_COST_UPD_FREQ
Control to set frequency of the cost updates for intrabc motion vectors, unsigned int parameter.
Definition aomcx.h:1366
@ AV1E_SET_AUTO_INTRA_TOOLS_OFF
Codec control to automatically turn off several intra coding tools, unsigned int parameter.
Definition aomcx.h:1427
@ AV1E_SET_ENABLE_RECT_TX
Codec control function to turn on / off rectangular transforms, int parameter.
Definition aomcx.h:919
@ AV1E_SET_ENABLE_DIST_WTD_COMP
Codec control function to turn on / off dist-wtd compound mode at sequence level, int parameter.
Definition aomcx.h:931
@ AV1E_SET_TIMING_INFO_TYPE
Codec control function to signal picture timing info in the bitstream, aom_timing_info_type_t paramet...
Definition aomcx.h:1175
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition aomcx.h:657
@ AV1E_SET_TIER_MASK
Control to set bit mask that specifies which tier each of the 32 possible operating points conforms t...
Definition aomcx.h:1271
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition aomcx.h:1025
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition aomcx.h:494
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition aomcx.h:1009
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition aomcx.h:1215
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition aomcx.h:1066
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition aomcx.h:1116
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition aomcx.h:1095
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition aomcx.h:423
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition aomcx.h:796
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition aomcx.h:312
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition aomcx.h:448
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition aomcx.h:1001
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition aomcx.h:252
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition aomcx.h:704
@ AV1E_SET_PARTITION_INFO_PATH
Codec control to set the path for partition stats read and write. const char * parameter.
Definition aomcx.h:1371
@ AV1E_SET_ENABLE_LOW_COMPLEXITY_DECODE
Codec control to enable the low complexity decode mode, unsigned int parameter. Value of zero means t...
Definition aomcx.h:1584
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition aomcx.h:855
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition aomcx.h:833
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition aomcx.h:1148
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition aomcx.h:883
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition aomcx.h:288
@ AV1E_SET_TARGET_SEQ_LEVEL_IDX
Control to set target sequence level index for a certain operating point (OP), int parameter Possible...
Definition aomcx.h:642
@ AV1E_SET_CHROMA_SAMPLE_POSITION
Codec control function to set chroma 4:2:0 sample position info, aom_chroma_sample_position_t paramet...
Definition aomcx.h:586
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition aomcx.h:1202
@ AV1E_SET_DELTAQ_STRENGTH
Set –deltaq-mode strength.
Definition aomcx.h:1406
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition aomcx.h:1208
@ AV1E_SET_LOOPFILTER_CONTROL
Codec control to control loop filter.
Definition aomcx.h:1415
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition aomcx.h:228
@ AV1E_ENABLE_RATE_GUIDE_DELTAQ
Codec control to enable the rate distribution guided delta quantization in all intra mode,...
Definition aomcx.h:1510
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition aomcx.h:386
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition aomcx.h:872
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition aomcx.h:1140
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition aomcx.h:1035
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition aomcx.h:1187
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition aomcx.h:750
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition aomcx.h:1229
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition aomcx.h:345
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition aomcx.h:985
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition aomcx.h:1193
@ AV1E_SET_VMAF_MODEL_PATH
Codec control function to set the path to the VMAF model used when tuning the encoder for VMAF,...
Definition aomcx.h:1300
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition aomcx.h:738
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition aomcx.h:725
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition aomcx.h:1113
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition aomcx.h:817
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition aomcx.h:533
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition aomcx.h:298
@ AV1E_SET_ENABLE_TX_SIZE_SEARCH
Control to turn on / off transform size search. Note: it can not work with non RD pick mode in real-t...
Definition aomcx.h:1395
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition aomcx.h:1253
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition aomcx.h:1278
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition aomcx.h:359
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition aomcx.h:279
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition aom.h:70
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
const char * aom_codec_version_str(void)
Return the version information (as a string)
aom_codec_err_t aom_codec_set_option(aom_codec_ctx_t *ctx, const char *name, const char *value)
Key & Value API.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition aom_codec.h:252
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:542
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
@ AOM_BITS_8
Definition aom_codec.h:336
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition aom_decoder.h:129
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition aom_encoder.h:1014
#define AOM_USAGE_ALL_INTRA
usage parameter analogous to AV1 all intra mode.
Definition aom_encoder.h:1018
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:943
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int usage)
Get the default configuration for a usage.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition aom_encoder.h:1016
#define AOM_CODEC_USE_HIGHBITDEPTH
Definition aom_encoder.h:80
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition aom_encoder.h:79
@ AOM_RC_ONE_PASS
Definition aom_encoder.h:177
@ AOM_RC_SECOND_PASS
Definition aom_encoder.h:179
@ AOM_RC_THIRD_PASS
Definition aom_encoder.h:180
@ AOM_RC_FIRST_PASS
Definition aom_encoder.h:178
@ AOM_KF_DISABLED
Definition aom_encoder.h:203
@ AOM_CODEC_PSNR_PKT
Definition aom_encoder.h:113
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:110
@ AOM_CODEC_STATS_PKT
Definition aom_encoder.h:111
Codec context structure.
Definition aom_codec.h:315
Encoder output packet.
Definition aom_encoder.h:122
size_t sz
Definition aom_encoder.h:127
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:123
double psnr[4]
Definition aom_encoder.h:145
aom_fixed_buf_t twopass_stats
Definition aom_encoder.h:140
aom_fixed_buf_t raw
Definition aom_encoder.h:156
union aom_codec_cx_pkt::@1 data
aom_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition aom_encoder.h:129
struct aom_codec_cx_pkt::@1::@2 frame
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition aom_encoder.h:136
void * buf
Definition aom_encoder.h:126
Initialization Configurations.
Definition aom_decoder.h:91
Encoder configuration structure.
Definition aom_encoder.h:387
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:489
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition aom_encoder.h:504
size_t sz
Definition aom_encoder.h:90
void * buf
Definition aom_encoder.h:89
Image Descriptor.
Definition aom_image.h:182
aom_chroma_sample_position_t csp
Definition aom_image.h:188
unsigned int y_chroma_shift
Definition aom_image.h:206
aom_img_fmt_t fmt
Definition aom_image.h:183
int stride[3]
Definition aom_image.h:216
unsigned char * img_data
Definition aom_image.h:230
unsigned int x_chroma_shift
Definition aom_image.h:205
unsigned int d_w
Definition aom_image.h:197
int bps
Definition aom_image.h:219
int monochrome
Definition aom_image.h:187
unsigned int d_h
Definition aom_image.h:198
unsigned char * planes[3]
Definition aom_image.h:215
int img_data_owner
Definition aom_image.h:231
int self_allocd
Definition aom_image.h:232
size_t sz
Definition aom_image.h:217
Rational Number.
Definition aom_encoder.h:164
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166
Encoder Config Options.
Definition aom_encoder.h:227
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition aom_encoder.h:243
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition aom_encoder.h:239
unsigned int disable_trellis_quant
disable trellis quantization
Definition aom_encoder.h:355
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition aom_encoder.h:235